﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using Jalal.Library.Utility;
using System.Collections.Generic;
using System.Drawing;
using BCGC.BLL.BusinessObject.Poll;
using BCGC.BLL.BusinessObject.Announcement;
using Jalal.Library.DataStructure;
using BCGC.BLL.BusinessObject.News;

public partial class _Default : PublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        LoadAnnouncements();
        LoadNews();
    }

    private void LoadNews()
    {
        ReadWriteCustomCollection<NewsItem> news = NewsItem.GetLatestNews(10);
        rptNews.DataSource = news;
        rptNews.DataBind();
    }

    private void LoadAnnouncements()
    {
        ReadWriteCustomCollection<AnnouncementItem> announcements = AnnouncementItem.GetLatestAnnouncements(10);
        rptAnnouncements.DataSource = announcements;
        rptAnnouncements.DataBind();
    }

    protected void Announcement_DataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            AnnouncementItem announcementItem = (AnnouncementItem)e.Item.DataItem;
            HyperLink hlkAnnouncementTitle = (HyperLink)e.Item.FindControl("hlkAnnouncementTitle");
            if (announcementItem != null && hlkAnnouncementTitle != null)
            {
                hlkAnnouncementTitle.NavigateUrl = CustomSiteMap.AnnouncementDetail + "?id=" 
                    + announcementItem.Id.ToString();
            }
        }
        else if (e.Item.ItemType == ListItemType.AlternatingItem)
        {
            AnnouncementItem announcementItem = (AnnouncementItem)e.Item.DataItem;
            HyperLink hlkAnnouncementTitle2 = (HyperLink)e.Item.FindControl("hlkAnnouncementTitle2");
            if (announcementItem != null && hlkAnnouncementTitle2 != null)
            {
                hlkAnnouncementTitle2.NavigateUrl = CustomSiteMap.AnnouncementDetail + "?id=" 
                    + announcementItem.Id.ToString();
            }
        }
    }

    protected void News_DataBound(object sender, RepeaterItemEventArgs e)
    {
        NewsItem newsItem = (NewsItem)e.Item.DataItem;
        if (e.Item.ItemType == ListItemType.Item)
        {
            HyperLink hlkNewsTitle = (HyperLink)e.Item.FindControl("hlkNewsTitle");
            if (newsItem != null && hlkNewsTitle != null)
            {
                hlkNewsTitle.NavigateUrl = CustomSiteMap.NewsDetail + "?id="
                    + newsItem.Id.ToString();
            }
        }
        else if (e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink hlkNewsTitle2 = (HyperLink)e.Item.FindControl("hlkNewsTitle2");
            if (newsItem != null && hlkNewsTitle2 != null)
            {
                hlkNewsTitle2.NavigateUrl = CustomSiteMap.NewsDetail + "?id="
                    + newsItem.Id.ToString();
            }
        }
    }
}
